package com.inossem.utils.signaturePad;

import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;

import com.inossem.utils.R;

/**
 * Created by leij on 2017/12/13.
 */

public class SignaturePadUtils {

    public static final int REQUEST_CODE = 20001;

    public static final String SIGNATURE_ROOT_PATH = "Inossem_Signature";

    public static final String SIGNATURE_FILE_PATH = "Signature_File_Path";

    public static final String AREA_PROMPT = "Area_Prompt";

    public static final String CLEAR_SIGNATURE = "Clear_Signature";

    public static final String MAKING_SIGNATURE = "Making_Signature";

    public static final String EXIT = "Back";

    public static final String TYPE = "Type";

    public static final String IMAGE_PATH = "Image_Path";

    public static final int TYPE_NORMAL = 0;

    public static final int TYPE_TRANSPARENT = 1;

    public static final int TYPE_TRANSPARENT_STRETCHING = 2;

    public static void showSignaturePad(Activity activity, String imagePath) {
        showSignaturePad(activity, imagePath, null, null, null, null, TYPE_NORMAL);
    }

    public static void showSignaturePad(Activity activity, String imagePath, String areaPromptText, String clearSignatureText, String makingSignatureText, String exitText, int type) {
        Intent intent = new Intent(activity, SignaturePadActivity.class);
        intent.putExtra(AREA_PROMPT, TextUtils.isEmpty(areaPromptText) ? activity.getResources().getString(R.string.utils_signature_pad_area_prompt) : areaPromptText);
        intent.putExtra(CLEAR_SIGNATURE, TextUtils.isEmpty(clearSignatureText) ? activity.getResources().getString(R.string.utils_signature_pad_clear_signature) : clearSignatureText);
        intent.putExtra(MAKING_SIGNATURE, TextUtils.isEmpty(makingSignatureText) ? activity.getResources().getString(R.string.utils_signature_pad_making_signature) : makingSignatureText);
        intent.putExtra(EXIT, TextUtils.isEmpty(exitText) ? activity.getResources().getString(R.string.utils_signature_pad_exit) : exitText);
        intent.putExtra(TYPE, type);
        intent.putExtra(IMAGE_PATH, imagePath);
        activity.startActivityForResult(intent, REQUEST_CODE);
    }

    public static boolean checkResult(int requestCode, int resultCode) {
        if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) {
            return true;
        } else {
            return false;
        }
    }

    public static String getSignatureFilePath(Intent data) {
        if (data.hasExtra(SignaturePadUtils.SIGNATURE_FILE_PATH)) {
            return data.getStringExtra(SignaturePadUtils.SIGNATURE_FILE_PATH);
        } else {
            return "";
        }
    }

}
